package formater

import (
	"encoding/hex"
	"strings"
)

// Hex 16进制格式化器
var Hex = NewFormater(
	"hex",
	hex.EncodeToString,
	hex.DecodeString,
)

var HexUpper = NewFormater(
	"hex_upper",
	func(b []byte) string {
		return strings.ToUpper(hex.EncodeToString(b))
	},
	func(s string) ([]byte, error) {
		decodeString, err := hex.DecodeString(s)
		if err != nil {
			return nil, err
		}
		return []byte(strings.ToUpper(string(decodeString))), nil
	},
)

var HexLower = NewFormater(
	"hex_lower",
	func(b []byte) string {
		return strings.ToLower(hex.EncodeToString(b))
	},
	func(s string) ([]byte, error) {
		decodeString, err := hex.DecodeString(s)
		if err != nil {
			return nil, err
		}
		return []byte(strings.ToLower(string(decodeString))), nil
	},
)
